package org.xyf.workflow.callback;

import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.Objects;

public class ExpenseProcessCallBack implements JavaDelegate {

    private static final Logger logger = LoggerFactory.getLogger(ExpenseProcessCallBack.class);

    @Override
    public void execute(DelegateExecution execution) {
        logger.info("user has approved the expense！");
        logger.info("processDefinitionId is {}",execution.getProcessDefinitionId());

        String currentActivityId = execution.getCurrentActivityId();

        String eventName = execution.getEventName();

        String approver = (String) execution.getVariable("assignee");

        logger.info("当前事件名称是: {};审批人为: {}",eventName,approver);

        Map<String, Object> variables = execution.getVariables();
        if(Objects.nonNull(variables)){
            logger.info("传递的参数是 : {}",variables);
        }

        if(currentActivityId.equals("handleApproval")){ //处理审批结果
            Boolean approved = (Boolean) execution.getVariable("approved");
            execution.setVariable("finalApproved", approved);
        } else { //自动报销
            logger.info("正在自动打款中!");
        }


    }
}
